package com.scau.beyondboy.controller;
import com.scau.beyondboy.model.BookEntity;
import com.scau.beyondboy.services.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
/**
 * Author:beyondboy
 * Gmail:xuguoli.scau@gmail.com
 * Date: 2015/12/13
 * Time: 20:47
 */
@Controller
@RequestMapping(value = "/book")
public class BookController
{
    @Autowired
    BookService bookService;
    @RequestMapping(value = "/show")
    public String show(HttpSession session)
    {
        session.setAttribute("bookList",bookService.findAllBook());
        return "showBook";
    }
    @RequestMapping(value = "/add")
    public String addBook(BookEntity bookEntity)
    {
        bookService.add(bookEntity);
        return "redirect:/book/show";
    }
    @RequestMapping(value = "/delete")
    public String deleteBook(@RequestParam int bookId)
    {
        System.out.println("bookId = [" + bookId + "]");
        bookService.deleteBook(bookId);
        return "redirect:/book/show";
    }
    @RequestMapping(value = "/addBook")
    public String addBook()
    {
        //bookService.add(bookEntity);
        return "addBook";
    }
    @RequestMapping(value="/findhandler")
    public  String findHandle(@RequestParam String find,HttpSession session)
    {
        session.setAttribute("find",bookService.findBook(Integer.parseInt(find)));
        return "showabook";
    }
}
